<template>
  <song-list
    :remove="true"
    :download="true"
    :loading="false"
    :songList="data"
    :totalCount="Muse_PlayList.length"
    @onplay="onplayHandler"
    @onchangePage="changePage"
    @onremove="removePlayList"
    @ondownload="downloadMusic"
  ></song-list>
</template>

<script>
import vuex from "vuex";


const { ipcRenderer } = window.require("electron");

import songList from "../components/songList";

const kuwoapi = vuex.createNamespacedHelpers("kuwoapi");
const wangyiyunapi = vuex.createNamespacedHelpers("wangyiyunapi");


// 引入方法
import music from "../function/music";

export default {
  data() {
    return {
      page: 0,
      Muse_PlayList: [],
    };
  },
  computed: {
    data() {
      return this.Muse_PlayList.slice(this.page * 30, this.page * 30 + 30);
    },
  },
  methods: {
    // 点击播放按钮
    onplayHandler(e) {
      let Muse_PlayList =
        ipcRenderer.sendSync("getStore", "Muse_PlayList") || [];
      this.$store.state.currentIndex = Muse_PlayList.findIndex(
        (_) => _.rid === e.rid
      );
      this.playMusic(Muse_PlayList[this.$store.state.currentIndex]);
    },

    // 下载按钮点击
    downloadMusic(e) {
      music.downloadMusic(e,this)
    },

    // 移除播放列表
    removePlayList(e) {
      // 更新缓存
      this.Muse_PlayList = this.Muse_PlayList.filter((_) => _.rid !== e.rid);
      // 更新本地
      ipcRenderer.send("setStore", "Muse_PlayList", this.Muse_PlayList);
    },

    // 播放按钮点击
    async playMusic(e) {
      music.playMusic(e,this)
    },

    // 换行
    changePage(page) {
      this.page = page - 1;
    },
  },
  created() {
    //   从本地获取下载列表
    this.Muse_PlayList =
      ipcRenderer.sendSync("getStore", "Muse_PlayList") || [];
  },
  components: {
    songList,
  },
};
</script>

<style lang="scss" scoped>
</style>